package com.joanzapata.pdfview.util;

import android.graphics.PointF;
import android.view.MotionEvent;
import android.view.View;

/* loaded from: classes.dex */
public class DragPinchListener implements View.OnTouchListener {
    private static final float MAX_CLICK_DISTANCE = 5.0f;
    private static final long MAX_CLICK_TIME = 500;
    private static final float MAX_DOUBLE_CLICK_TIME = 280.0f;
    private static final int POINTER1 = 0;
    private static final int POINTER2 = 1;
    private float dragLastX;
    private float dragLastY;
    private long lastClickTime;
    private float lastDownX;
    private float lastDownY;
    private OnDoubleTapListener onDoubleTapListener;
    private OnDragListener onDragListener;
    private OnPinchListener onPinchListener;
    private float pointer2LastX;
    private float pointer2LastY;
    private State state = State.NONE;
    private float zoomLastDistance;

    /* loaded from: classes.dex */
    public interface OnDoubleTapListener {
        void onDoubleTap(float f, float f2);
    }

    /* loaded from: classes.dex */
    public interface OnDragListener {
        void endDrag(float f, float f2);

        void onDrag(float f, float f2);

        void startDrag(float f, float f2);
    }

    /* loaded from: classes.dex */
    public interface OnPinchListener {
        void onPinch(float f, PointF pointF);
    }

    /* loaded from: classes.dex */
    enum State {
        NONE,
        ZOOM,
        DRAG
    }

    /* JADX WARN: Code restructure failed: missing block: B:22:0x0061, code lost:
        if (r8 != 2) goto L15;
     */
    @Override // android.view.View.OnTouchListener
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public boolean onTouch(android.view.View r8, android.view.MotionEvent r9) {
        /*
            r7 = this;
            int r8 = r9.getAction()
            r0 = 1
            if (r8 == 0) goto Lbb
            if (r8 == r0) goto L77
            r1 = 2
            if (r8 == r1) goto L55
            r1 = 5
            if (r8 == r1) goto L3c
            r1 = 6
            if (r8 == r1) goto L2e
            r1 = 261(0x105, float:3.66E-43)
            if (r8 == r1) goto L22
            r9 = 262(0x106, float:3.67E-43)
            if (r8 == r9) goto L1c
            goto Lce
        L1c:
            com.joanzapata.pdfview.util.DragPinchListener$State r8 = com.joanzapata.pdfview.util.DragPinchListener.State.DRAG
            r7.state = r8
            goto Lce
        L22:
            r7.startDrag(r9)
            r7.startZoom(r9)
            com.joanzapata.pdfview.util.DragPinchListener$State r8 = com.joanzapata.pdfview.util.DragPinchListener.State.ZOOM
            r7.state = r8
            goto Lce
        L2e:
            float r8 = r7.pointer2LastX
            r7.dragLastX = r8
            float r8 = r7.pointer2LastY
            r7.dragLastY = r8
            com.joanzapata.pdfview.util.DragPinchListener$State r8 = com.joanzapata.pdfview.util.DragPinchListener.State.DRAG
            r7.state = r8
            goto Lce
        L3c:
            r8 = 0
            float r1 = r9.getX(r8)
            r7.pointer2LastX = r1
            float r8 = r9.getY(r8)
            r7.pointer2LastY = r8
            r7.startDrag(r9)
            r7.startZoom(r9)
            com.joanzapata.pdfview.util.DragPinchListener$State r8 = com.joanzapata.pdfview.util.DragPinchListener.State.ZOOM
            r7.state = r8
            goto Lce
        L55:
            int[] r8 = com.joanzapata.pdfview.util.DragPinchListener.AnonymousClass1.$SwitchMap$com$joanzapata$pdfview$util$DragPinchListener$State
            com.joanzapata.pdfview.util.DragPinchListener$State r2 = r7.state
            int r2 = r2.ordinal()
            r8 = r8[r2]
            if (r8 == r0) goto L64
            if (r8 == r1) goto L73
            goto Lce
        L64:
            float r8 = r9.getX(r0)
            r7.pointer2LastX = r8
            float r8 = r9.getY(r0)
            r7.pointer2LastY = r8
            r7.zoom(r9)
        L73:
            r7.drag(r9)
            goto Lce
        L77:
            com.joanzapata.pdfview.util.DragPinchListener$State r8 = com.joanzapata.pdfview.util.DragPinchListener.State.NONE
            r7.state = r8
            r7.endDrag()
            float r3 = r7.lastDownX
            float r4 = r7.lastDownY
            float r5 = r9.getX()
            float r6 = r9.getY()
            r1 = r7
            r2 = r9
            boolean r8 = r1.isClick(r2, r3, r4, r5, r6)
            if (r8 == 0) goto Lce
            long r1 = java.lang.System.currentTimeMillis()
            long r3 = r7.lastClickTime
            long r1 = r1 - r3
            float r8 = (float) r1
            r1 = 1133248512(0x438c0000, float:280.0)
            int r8 = (r8 > r1 ? 1 : (r8 == r1 ? 0 : -1))
            if (r8 >= 0) goto Lb4
            com.joanzapata.pdfview.util.DragPinchListener$OnDoubleTapListener r8 = r7.onDoubleTapListener
            if (r8 == 0) goto Laf
            float r1 = r9.getX()
            float r9 = r9.getY()
            r8.onDoubleTap(r1, r9)
        Laf:
            r8 = 0
            r7.lastClickTime = r8
            goto Lce
        Lb4:
            long r8 = java.lang.System.currentTimeMillis()
            r7.lastClickTime = r8
            goto Lce
        Lbb:
            r7.startDrag(r9)
            com.joanzapata.pdfview.util.DragPinchListener$State r8 = com.joanzapata.pdfview.util.DragPinchListener.State.DRAG
            r7.state = r8
            float r8 = r9.getX()
            r7.lastDownX = r8
            float r8 = r9.getY()
            r7.lastDownY = r8
        Lce:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.joanzapata.pdfview.util.DragPinchListener.onTouch(android.view.View, android.view.MotionEvent):boolean");
    }

    /* renamed from: com.joanzapata.pdfview.util.DragPinchListener$1  reason: invalid class name */
    /* loaded from: classes.dex */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$joanzapata$pdfview$util$DragPinchListener$State = new int[State.values().length];

        static {
            try {
                $SwitchMap$com$joanzapata$pdfview$util$DragPinchListener$State[State.ZOOM.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$joanzapata$pdfview$util$DragPinchListener$State[State.DRAG.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
        }
    }

    private void endDrag() {
        this.onDragListener.endDrag(this.dragLastX, this.dragLastY);
    }

    private void startZoom(MotionEvent motionEvent) {
        this.zoomLastDistance = distance(motionEvent);
    }

    private void zoom(MotionEvent motionEvent) {
        float distance = distance(motionEvent);
        OnPinchListener onPinchListener = this.onPinchListener;
        if (onPinchListener != null) {
            onPinchListener.onPinch(distance / this.zoomLastDistance, new PointF(motionEvent.getX(0), motionEvent.getY(0)));
        }
        this.zoomLastDistance = distance;
    }

    private void startDrag(MotionEvent motionEvent) {
        this.dragLastX = motionEvent.getX(0);
        this.dragLastY = motionEvent.getY(0);
        this.onDragListener.startDrag(this.dragLastX, this.dragLastY);
    }

    private void drag(MotionEvent motionEvent) {
        float x = motionEvent.getX(0);
        float y = motionEvent.getY(0);
        OnDragListener onDragListener = this.onDragListener;
        if (onDragListener != null) {
            onDragListener.onDrag(x - this.dragLastX, y - this.dragLastY);
        }
        this.dragLastX = x;
        this.dragLastY = y;
    }

    private float distance(MotionEvent motionEvent) {
        if (motionEvent.getPointerCount() < 2) {
            return 0.0f;
        }
        return PointF.length(motionEvent.getX(0) - motionEvent.getX(1), motionEvent.getY(0) - motionEvent.getY(1));
    }

    private boolean isClick(MotionEvent motionEvent, float f, float f2, float f3, float f4) {
        if (motionEvent == null) {
            return false;
        }
        return motionEvent.getEventTime() - motionEvent.getDownTime() < MAX_CLICK_TIME && PointF.length(f - f3, f2 - f4) < MAX_CLICK_DISTANCE;
    }

    public void setOnDragListener(OnDragListener onDragListener) {
        this.onDragListener = onDragListener;
    }

    public void setOnPinchListener(OnPinchListener onPinchListener) {
        this.onPinchListener = onPinchListener;
    }

    public void setOnDoubleTapListener(OnDoubleTapListener onDoubleTapListener) {
        this.onDoubleTapListener = onDoubleTapListener;
    }
}
